from append_trunk_to_PYTHONPATH import preparePath
preparePath()

import unittest
from direct.showbase.DirectObject import DirectObject
import direct.directbase.DirectStart
from gameGui.SklGui import InventoryGui
import re

class InventoryTests(unittest.TestCase):
    
    inventory = None
    
    def setUp(self):
        self.inventory = InventoryGui(DirectObject())
    
    
    def test_initializingWithDirectObject(self):
####### out of curiosity:
        self.failUnless(
            isinstance(self.inventory._directObjectParent, DirectObject)
        )
        
    def test_addNewItem(self):
####### adding an item - by default, only one:
        str1 = 'yudfcghiusagdych x67676x x76878 x786878 x677   x7x x67'
        self.inventory._addNewItem(str1)
        
        labelList = [
            label['text'] for label in self.inventory._directObjectParent.myScrolledList['items']
        ]
        
        str2 = str1 + ' x1'
        self.failUnless(str2 in labelList)
        
        newLabel = labelList[labelList.index(str2)]
        labelParts = re.split(' x([0-9]+)$', newLabel)
        
        self.failUnless(labelParts[1] == str(1))
        
####### adding several new items:
        str1 = 'Crocodile in yellow tutu'
        self.inventory._addNewItem(str1, 456709876)
        
        labelList = [
            label['text'] for label in self.inventory._directObjectParent.myScrolledList['items']
        ]
        
        str2 = str1 + ' x456709876'
        self.failUnless(str2 in labelList)
        
    def test_removeAll(self):
        self.inventory._removeAll()
        
        labelList = [
            label['text'] for label in self.inventory._directObjectParent.myScrolledList['items']
        ]
        
        self.failUnless(len(labelList) == 0)
        
        
def main():
    unittest.main()
    
if __name__ == '__main__':
    main()